"""
@Time ： 2021/11/11 10:07
@Auth ： ChenZhangKun
"""
from selenium import webdriver
from selenium.webdriver.common.by import By

webDriver = webdriver.Chrome(r'D:\sofwares\chrom\chromedriver.exe')

webDriver.get('http://cdn1.python3.vip/files/selenium/sample1.html')
elements = webDriver.find_elements(By.CSS_SELECTOR, "div")
for el in elements:
    print(el.text)

# 通过id选择
element = webDriver.find_element(By.CSS_SELECTOR, "#searchtext")
print(element.get_attribute("outerHTML"))

# 选择id的直接子元素
cElements = webDriver.find_elements(By.CSS_SELECTOR, "#container>div")
# x选择container所有直接子元素
ccElements = webDriver.find_elements(By.CSS_SELECTOR, "#container div")
for c in cElements:
    print(c.get_attribute("outerHTML"))

for cc in  ccElements:
    print(cc.get_attribute("outerHTML"))
